<html>
<head>
<script src="../encrypted-media/encrypted-media-utils.js"></script>
</head>
<body>
<script>
    var initDataType;
    var initData;
    var mediaKeySession;

    window.onmessage = function(e) {
        if (e.data.comm == 'init') {
            navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
                        initDataType = access.getConfiguration().initDataTypes[0];
                initData = getInitData(initDataType);
                return access.createMediaKeys();
            }).then(function(mediaKeys) {
                mediaKeySession = mediaKeys.createSession();
                return mediaKeySession.generateRequest(initDataType, initData);
            }).then(function() {
                window.parent.postMessage({comm: 'init-completed'}, '*');
            });
        } else if (e.data.comm == 'close') {
            window.parent.postMessage({comm: 'close-received'}, '*');
            mediaKeySession.close().catch(function(error) {
                window.parent.postMessage({result: 'error'}, '*');
            });
        }
    };
</script>'
</body>
</html>
